package com.example.freshmanapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.freshmanapp.R;
import com.example.freshmanapp.polo.News;

import org.w3c.dom.Text;

import java.util.List;

public class NewsAdapter extends BaseAdapter {
    LayoutInflater inflater;
    Context context;
    List<News> list;

    public NewsAdapter( Context context, List<News> list) {
        this.context = context;
        this.list = list;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView=inflater.inflate(R.layout.item_listview,null);
        TextView tv_title=(TextView) convertView.findViewById(R.id.tv_title);
//找控件
        TextView tv_date=(TextView) convertView.findViewById(R.id.tv_date);
        News news=list.get(position);
        tv_title.setText(news.getTitle());
        tv_date.setText(news.getDate().toString());
        return convertView;
    }
}
